import { createApp, h } from 'vue';
import Toast from './Toast.vue';

const toastContainer = document.createElement('div');
toastContainer.id = 'toast-container';
document.body.appendChild(toastContainer);

const showToast = (message, type = 'info', duration = 3000) => {
    const app = createApp({
        render: () => h(Toast, { message, type, duration })
    });

    const vm = app.mount(document.createElement('div'));
    toastContainer.appendChild(vm.$el);

    setTimeout(() => {
        toastContainer.removeChild(vm.$el);
        app.unmount();
    }, duration);
};

export default {
    info: (message, duration) => showToast(message, 'info', duration),
    success: (message, duration) => showToast(message, 'success', duration),
    error: (message, duration) => showToast(message, 'error', duration)
};